//
//  PostListViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/10.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "GKPhotoBrowser.h"

#import "PostListHeaderView.h"
#import "TT_BaseNaviView.h"
#import "PostEvaluateCell.h"
//#import "PostEvaluateLookMoreCell.h"

#import "PostSectionHeaderView.h"
#import "PostSectionFooterView.h"
#import "BA_CommunityInputTextView.h"

#import "PostPublishViewController.h"
#import "PostDetailViewController.h"

#import "PostListViewController.h"

@interface PostListViewController ()<UITableViewDelegate, UITableViewDataSource, GKPhotoBrowserDelegate, BA_BottomInputViewDelegate, UITextViewDelegate>


@property (nonatomic, strong) TT_BaseNaviView *naviView;

@property (nonatomic, strong) UITableView *tableview;

@property (nonatomic, strong) PostListHeaderView *headerView;
@property (nonatomic, strong) CommunityThemeModel *headModel;

@property (nonatomic, strong) UIButton *addBtn;

@property (nonatomic, assign) NSInteger pageSize;
@property (nonatomic, assign) NSInteger pageNum;
@property (nonatomic, strong) NSMutableArray <CommonPostModel*>* dataArray;

@property (nonatomic, assign) NSInteger selectIndex;
@property (nonatomic, strong) BA_CommunityInputTextView *footView;


@property (nonatomic, strong) dispatch_group_t group;
@property (nonatomic, copy) NSString * remark;


@end

@implementation PostListViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIWindow * keyWindow = [UIApplication sharedApplication].keyWindow;
    [keyWindow addSubview:self.footView];
    [self.footView hideView];

    
    [self initView];
    
    self.remark = @"2";
    [self refreshParam];
    [self request_data];
}

- (void)refreshParam {
    self.pageSize = 10;
    self.pageNum = 1;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[IQKeyboardManager sharedManager] setEnableAutoToolbar:NO];
    [[IQKeyboardManager sharedManager] setEnable:NO];

}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[IQKeyboardManager sharedManager] setEnableAutoToolbar:YES];
    [[IQKeyboardManager sharedManager] setEnable:YES];

    [self.footView hideView];
}

- (void)textViewDidEndEditing:(UITextView *)textView {
    
    [self.footView hideView];
}

-(BOOL)textViewShouldEndEditing:(UITextView *)textView {
    
    [self.footView hideView];
    return YES;
}

-(void)BA_BottomInputViewSendTextMessage:(NSString *)message {
    [self request_postEvaWithIndex:self.selectIndex AndContent:message];
}


- (void)request_data {
    
    [SVProgressHUD showWithStatus:@"正在请求数据"];
    self.group = dispatch_group_create();

    dispatch_group_enter(self.group);
    dispatch_group_async(self.group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self request_postList];
    });
    
    dispatch_group_enter(self.group);
    dispatch_group_async(self.group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self request_ThemeData];
    });

    dispatch_group_notify(self.group, dispatch_get_main_queue(), ^{
        
        [SVProgressHUD dismiss];
        [self.tableview.mj_header endRefreshing];
        [self.tableview.mj_footer endRefreshing];
        
        [self.tableview reloadData];

    });
}

- (void)initView {
    
    self.navigationController.navigationBarHidden = YES;
    #if RT_INTERACTIVE_PUSH
        self.rt_navigationController.rt_enableInteractivePush = YES;
    #endif
    self.rt_disableInteractivePop = NO;
    
    self.view.backgroundColor = UIColor.whiteColor;
    
    self.tableview;
    
    [self.view addSubview:self.naviView];
    [self.naviView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(NavBar_Height + kStatusBarHeight);

    }];
    
    [self.view addSubview:self.addBtn];
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-100);
        make.right.mas_equalTo(-5);
        make.height.width.mas_equalTo(68);
    }];

    [self initViewAction];
}

- (void)initViewAction {
    
    WEAKSELF
    self.headerView.PostListHeaderViewBlock = ^(PostListHeaderViewActionType type) {
      
        switch (type) {
            case PostListHeaderViewActionType_back:{
                [weakSelf.navigationController popViewControllerAnimated:YES];
                
            } break;
            case PostListHeaderViewActionType_hot:{

                weakSelf.remark = @"2";
                [weakSelf refreshParam];
                [weakSelf request_data];
            } break;
            case PostListHeaderViewActionType_new:{

                weakSelf.remark = @"3";
                [weakSelf refreshParam];
                [weakSelf request_data];
            } break;
            default:
                break;
        }
    };
}

- (void)addPostAction {
    
    PostPublishViewController *vc = [[PostPublishViewController alloc] init];
    CommunityThemeModel *model = [[CommunityThemeModel alloc] init];
    model.themeId = self.headModel.themeId;
    model.themeTitle = self.headModel.themeTitle;
    vc.model = model;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)goBack {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)showImageWithArray:(NSArray *)imageUrls index:(NSInteger)index {
    NSMutableArray *photos = [NSMutableArray new];
    
    [imageUrls enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        GKPhoto *photo = [GKPhoto new];
        photo.url = [NSURL URLWithString:obj];
        [photos addObject:photo];
    }];
    
    GKPhotoBrowser *browser = [GKPhotoBrowser photoBrowserWithPhotos:photos currentIndex:index];
    browser.showStyle = GKPhotoBrowserShowStyleNone;
    browser.hideStyle = GKPhotoBrowserHideStyleZoomScale;
    
    browser.delegate  = self;
    [browser showFromVC:self];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat naviH = TTScreenWidth * 0.52 - kStatusBarHeight - NavBar_Height;

//    导航栏设置
    CGFloat alpha = (scrollView.contentOffset.y)/(naviH - kStatusBarHeight - NavBar_Height);
    [self.naviView.naviBgImageView setImage:[Utilities imageWithColor:[[UIColor whiteColor] colorWithAlphaComponent:alpha]]];
    self.naviView.titleLab.alpha = alpha;
    
    if (alpha > 0.5) {
        [self.naviView.backBtn setImage:[UIImage imageNamed:@"public_back_black"] forState:UIControlStateNormal];
    } else {
        [self.naviView.backBtn setImage:[UIImage imageNamed:@"public_back_white"] forState:UIControlStateNormal];
    }
}

    
#pragma mark UITableviewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    //判断显示几个评论
    NSInteger count = 0;
    if (self.dataArray[section].sysPostChildList.count > 2) {
        count = 2;
    } else {
        count = self.dataArray[section].sysPostChildList.count;
    }
    return count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return self.dataArray[section].itemHeight;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return self.dataArray[indexPath.section].sysPostChildList[indexPath.row].itemHeight + 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (self.dataArray[section].sysPostChildList.count > 0) {
        return 45;
    } else {
        return 15;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    PostSectionHeaderView *sectionHeader = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"PostSectionHeaderView"];
    sectionHeader.contentView.backgroundColor = UIColor.whiteColor;
    
    WEAKSELF
    sectionHeader.PostSectionHeaderViewBlock = ^(PostSectionHeaderActionType type, NSInteger index) {
      
        switch (type) {
            case PostSectionHeaderActionType_userIcon:{
                if (weakSelf.dataArray[section].userHeadUrl.length > 0) {
                    [weakSelf showImageWithArray:@[weakSelf.dataArray[section].userHeadUrl] index:index];
                }
            } break;
            case PostSectionHeaderActionType_image:{
                if (weakSelf.dataArray[section].photoArray.count > 0) {
                    [weakSelf showImageWithArray:weakSelf.dataArray[section].photoArray index:index];
                }
            } break;
            case PostSectionHeaderActionType_theme:{

                PostListViewController *vc = [[PostListViewController alloc] init];
                vc.tid = weakSelf.dataArray[section].themeId;
                [weakSelf.navigationController pushViewController:vc animated:YES];

            } break;
            case PostSectionHeaderActionType_eva:{
                
                weakSelf.selectIndex = section;
                [weakSelf.footView showView];
                [weakSelf.footView.textView becomeFirstResponder];
                
            } break;
            case PostSectionHeaderActionType_thumb:{
                
                weakSelf.selectIndex = section;
                [weakSelf request_postThumbWithIndex:section];

            } break;
            default:
                break;
        }
        
    };
    
    [sectionHeader fillWithModel:self.dataArray[section]];
    
    [sectionHeader addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        PostDetailViewController *vc = [[PostDetailViewController alloc] init];
        vc.pid = weakSelf.dataArray[section].pid;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    
    return sectionHeader;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    PostSectionFooterView*sectionFooter = [[NSBundle mainBundle] loadNibNamed:@"PostSectionFooterView" owner:nil options:nil].firstObject;
    sectionFooter.contentView.backgroundColor = UIColor.whiteColor;
    
    sectionFooter.mainTitleLab.text = [NSString stringWithFormat:@"查看共%lu条评论",(unsigned long)self.dataArray[section].replyCount];
    
    WEAKSELF
    [sectionFooter addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        PostDetailViewController *vc = [[PostDetailViewController alloc] init];
        vc.pid = weakSelf.dataArray[section].pid;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    
    return sectionFooter;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PostEvaluateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PostEvaluateCellID"];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    [cell fillWithModel:self.dataArray[indexPath.section].sysPostChildList[indexPath.row]];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    PostDetailViewController *vc = [[PostDetailViewController alloc] init];
    vc.pid = self.dataArray[indexPath.section].pid;
    [self.navigationController pushViewController:vc animated:YES];
}

- (BA_CommunityInputTextView *)footView {
    if (_footView == nil) {
        _footView = [[BA_CommunityInputTextView alloc]init];
        _footView.delegate = self;
        _footView.textView.delegate = self;
    }
    return _footView;
}

- (UITableView *)tableview {
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.backgroundColor =  UIColor.clearColor;
        
        _tableview.showsHorizontalScrollIndicator = NO;
        _tableview.showsVerticalScrollIndicator = NO;
        
        _tableview.estimatedSectionHeaderHeight = 0;
        _tableview.estimatedSectionFooterHeight = 0;
        _tableview.estimatedRowHeight = 0;
        
        [_tableview registerNib:[UINib nibWithNibName:@"PostEvaluateCell" bundle:nil] forCellReuseIdentifier:@"PostEvaluateCellID"];
        
        [_tableview registerNib:[UINib nibWithNibName:@"PostEvaluateLookMoreCell" bundle:nil] forCellReuseIdentifier:@"PostEvaluateLookMoreCellID"];

        [_tableview registerNib:[UINib nibWithNibName:@"PostSectionHeaderView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"PostSectionHeaderView"];
        
        [_tableview registerNib:[UINib nibWithNibName:@"PostSectionFooterView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"PostSectionFooterView"];

        
        [self.view addSubview:_tableview];
        
        [_tableview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.bottom.mas_equalTo(0);
        }];
        
        self.headerView.frame = CGRectMake(0, 0, TTScreenWidth, [PostListHeaderView calculateHeight]);
        _tableview.tableHeaderView = self.headerView;
        self.headerView.autoresizingMask = UIViewAutoresizingNone;
        
        if([_tableview respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
            if (@available(iOS 11.0, *)) {
                _tableview.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;
            } else {
                // Fallback on earlier versions
            }
        }
        
        WEAKSELF
        _tableview.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
            [weakSelf refreshParam];
            [weakSelf request_data];
        }];

        _tableview.mj_footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
            weakSelf.pageNum ++;
            [weakSelf request_data];
        }];
        
        _tableview.mj_footer.ignoredScrollViewContentInsetBottom = Is_IPhoneX ? Bottom_SafeHeight : CGFLOAT_MIN;

    }
    return _tableview;
}

- (TT_BaseNaviView *)naviView {
    if (!_naviView) {
        _naviView = [[NSBundle mainBundle] loadNibNamed:@"TT_BaseNaviView"owner:nil options:nil].firstObject;
        [_naviView.backBtn setImage:[UIImage imageNamed:@"public_back_white"] forState:UIControlStateNormal];
        _naviView.titleLab.alpha = 0.0f;
        [_naviView.backBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    }
    return _naviView;
}
    
- (PostListHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[NSBundle mainBundle] loadNibNamed:@"PostListHeaderView" owner:nil options:nil].firstObject;
    }
    return _headerView;
}

- (UIButton *)addBtn {
    if (!_addBtn) {
        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addBtn setImage:[UIImage imageNamed:@"add_post"] forState:UIControlStateNormal];
        [_addBtn addTarget:self action:@selector(addPostAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addBtn;
}

- (void)request_postList {

    NSMutableDictionary *dic = @{}.mutableCopy;
    NSMutableDictionary *t = @{}.mutableCopy;

    [dic setValue:@(self.pageNum) forKey:@"pageNum"];
    [dic setValue:@(self.pageSize) forKey:@"pageSize"];
    
    [t setValue:[TTUserModel sharedObject].userId forKey:@"replyUserId"];
    
    [t setValue:self.tid forKey:@"themeId"];
    [t setValue:@"2" forKey:@"isDel"];
    [t setValue:@"1" forKey:@"type"];
    [t setValue:@"3" forKey:@"status"];
    [t setValue:self.remark forKey:@"remark"];
    [dic setValue:t forKey:@"t"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_SysPosts];
    
    WEAKSELF
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
                
        if ([data isKindOfClass:[NSDictionary class]]) {

            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                NSDictionary *resultDic = [data valueForKey:@"data"];
                
                if ([resultDic isKindOfClass:[NSDictionary class]]) {
                    
                    NSArray *list = [resultDic valueForKey:@"list"];
                    
                    if ([list isKindOfClass:[NSArray class]]) {
                        
                        if (weakSelf.pageNum == 1) {
                            weakSelf.dataArray = @[].mutableCopy;
                            
                            if (list.count == 0) {
                                
                                [TT_Alert alert:@"当前主题无帖子" cancleBtnTitle:@"返回" cancleAction:^{
                                    [weakSelf.navigationController popViewControllerAnimated:YES];
                                } doneBtnTitle:@"去发帖" doneAction:^{
                                    [weakSelf addPostAction];
                                }];
                            }
                        }
                            
                        for (NSDictionary *dic in list) {
                            CommonPostModel *model = [CommonPostModel modelWithDictionary:dic];

                            NSArray *sysMediaList = [dic valueForKey:@"sysMediaList"];
                            if ([sysMediaList isKindOfClass:[NSArray class]]) {
                                model.sysMediaList = @[].mutableCopy;
                                model.photoArray = @[].mutableCopy;
                                for (id mediaDic in sysMediaList) {
                                    
                                    CommonMediaModel *mediaModel = [[CommonMediaModel alloc] init];
                                    if ([mediaDic isKindOfClass:[NSDictionary class]]) {
                                        NSDictionary *media = mediaDic;
                                        mediaModel = [CommonMediaModel modelWithDictionary:media];
                                        [model.photoArray addObject:mediaModel.url];

                                    }
                                    
                                    if ([mediaDic isKindOfClass:[NSString class]]) {
                                        NSString *media = mediaDic;
                                        mediaModel.url = media;
                                        [model.photoArray addObject:media];
                                    }
                                    
                                    [model.sysMediaList addObject:mediaModel];
                                }
                            }
                            
                            NSArray *sysPostChildList = [dic valueForKey:@"sysPostChildList"];
                            if ([sysPostChildList isKindOfClass:[NSArray class]]) {
                                
                                //最多展示两条，所以就不需要那么多循环  省点时间
                                if (sysPostChildList.count > 2) {
                                    sysPostChildList = [sysPostChildList subarrayWithRange:NSMakeRange(0, 2)];
                                }
                                
                                model.sysPostChildList = @[].mutableCopy;
                                for (NSDictionary * evaDic in sysPostChildList) {
                                    CommunityEvaModel *evaModel = [CommunityEvaModel modelWithDictionary:evaDic];
                                    
                                    //富文本
                                    NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@:%@",evaModel.userNickName,evaModel.content]];
                                    NSRange nameRange = NSMakeRange(0, evaModel.userNickName.length);
                                    NSRange contentRange = NSMakeRange(evaModel.userNickName.length + 1,evaModel.content.length);
                                    // 设置字体大小
                                    [attrStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:nameRange];
                                    [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:contentRange];
                                    evaModel.evaContentAttr = attrStr;
                                    
                                    evaModel.content = [NSString stringWithFormat:@"%@:%@",evaModel.userNickName,evaModel.content];

                                    CGFloat itemHeight = [Utilities getStringHeightWithText:evaModel.content font:[UIFont systemFontOfSize:13] viewWidth:(TTScreenWidth-48)];
                                    
                                    if (itemHeight > 30) {
                                        evaModel.itemHeight = 30;
                                    } else {
                                        evaModel.itemHeight = [Utilities getStringHeightWithText:evaModel.content font:[UIFont systemFontOfSize:13] viewWidth:(TTScreenWidth-48)];
                                    }
                                    
                                    [model.sysPostChildList addObject:evaModel];
                                }
                            }
                            
                            //自定义处理区域
                            model.content = [NSString stringWithFormat:@"【%@】%@",model.themeTitle,model.title];
                            model.textHeight = [Utilities getStringHeightWithText:model.content font:[UIFont systemFontOfSize:14] viewWidth:(TTScreenWidth - 28)];
                            
                            if (model.sysMediaList.count > 0) {
                                model.imageHeight = (TTScreenWidth - 32)/3 + 10;
                            } else {
                                model.imageHeight = CGFLOAT_MIN;
                            }
                            model.itemHeight = [PostSectionHeaderView calculateHWithModel:model];

                            [weakSelf.dataArray addObject:model];
                        }
                            
                        
                    } else {
                        
                    }
                }
            }
        }
        dispatch_group_leave(self.group);
    } FailedBlock:^(NSError * _Nonnull error) {
        dispatch_group_leave(self.group);
    }];
}

- (void)request_ThemeData {

    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:self.tid forKey:@"themeId"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_ThemeDetail];
        
    WEAKSELF
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        
        if ([data isKindOfClass:[NSDictionary class]]) {

            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                NSDictionary *resultDic = [data valueForKey:@"data"];
                if ([resultDic isKindOfClass:[NSDictionary class]]) {
                        
                    weakSelf.headModel = [CommunityThemeModel modelWithDictionary:resultDic];
                    [weakSelf.headerView fillWithModel:weakSelf.headModel];
                    weakSelf.naviView.titleLab.text = weakSelf.headModel.themeTitle;
                }
            }
        }
        dispatch_group_leave(self.group);
    } FailedBlock:^(NSError * _Nonnull error) {
        dispatch_group_leave(self.group);

    }];
}

- (void)request_postEvaWithIndex:(NSInteger)index AndContent:(NSString *)content {
        
    CommonPostModel *model = self.dataArray[index];
    
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:content forKey:@"content"];

    [dic setValue:model.pid forKey:@"baseId"];
    [dic setValue:@"2" forKey:@"level"];
    [dic setValue:model.source forKey:@"source"];
    [dic setValue:model.userId forKey:@"userId"];
    
    //操作类型（1：评论，2：点赞，3：删除，4：下架，5：取消点赞）必传
    [dic setValue:@"1" forKey:@"mold"];

    //类型（1：谈婚，2：论嫁，3：问答）必传
    [dic setValue:@"1" forKey:@"type"];
    //层级（1,2,3）必传
    [dic setValue:@"2" forKey:@"replySource"];
    [dic setValue:[TTUserModel sharedObject].userId forKey:@"replyUserId"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_CommonEva];
    
    WEAKSELF
    [SVProgressHUD showWithStatus:@"正在发布评论"];
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {

        [[TTNoResultManager shareManager] hideNoResultWithView:weakSelf.tableview];
        
        [SVProgressHUD dismiss];
        if ([data isKindOfClass:[NSDictionary class]]) {

            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                weakSelf.footView.textView.text = @"";
                [weakSelf.view endEditing:YES];
                
                [weakSelf request_data];
                
            } else {
                
                [SVProgressHUD showErrorWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            }
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
    }];
}


- (void)request_postThumbWithIndex:(NSInteger)index {
        
    CommonPostModel *model = self.dataArray[index];

    NSMutableDictionary *dic = @{}.mutableCopy;

    //点赞帖子
    [dic setValue:model.pid forKey:@"baseId"];
    [dic setValue:@"1" forKey:@"level"];
    [dic setValue:model.source forKey:@"source"];
    [dic setValue:model.userId forKey:@"userId"];

    
    //操作类型（1：评论，2：点赞，3：删除，4：下架，5：取消点赞）必传
    if (model.isZan.length > 0) {
        [dic setValue:@"5" forKey:@"mold"];
        [dic setValue:model.isZan forKey:@"otherId"];
    } else {
        [dic setValue:@"2" forKey:@"mold"];
    }

    //类型（1：谈婚，2：论嫁，3：问答）必传
    [dic setValue:@"1" forKey:@"type"];
    //层级（1,2,3）必传
    [dic setValue:@"2" forKey:@"replySource"];
    [dic setValue:[TTUserModel sharedObject].userId forKey:@"replyUserId"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_CommonEva];
    
    WEAKSELF
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {

        [[TTNoResultManager shareManager] hideNoResultWithView:weakSelf.tableview];
        
        if ([data isKindOfClass:[NSDictionary class]]) {

            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                
                NSString *isZan = [data valueForKey:@"data"];
                if ([isZan isKindOfClass:[NSString class]]) {
                    
                    model.isZan = isZan;
                    if (isZan.length > 0) {
                        model.likes++;
                    } else {
                        model.likes--;
                    }
                    
                    [weakSelf.tableview reloadData];
                }
            } else {
                
                [SVProgressHUD showErrorWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            }
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {

    }];
}

@end
